//
//  XSView.m
//  MeiLiYiChu
//
//  Created by mac on 16/2/25.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "XSView.h"

@implementation XSView
-(id)initWithBool:(BOOL)isShared withString:(NSString*)text
{
    self =[super init];
    if (self)
    {
        self =[[XSView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64)];
        self.backgroundColor =backColor;
        
        UILabel * lab =[[UILabel alloc]init];
        lab.center =CGPointMake(self.center.x, self.center.y+10);
        lab.bounds= CGRectMake(0, 0, 150, 40);
        lab.text =text;
        lab.font =[UIFont systemFontOfSize:20];
        lab.textAlignment =NSTextAlignmentCenter;
        [self addSubview:lab];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.center =CGPointMake(30, self.center.y+10);
        button.bounds =CGRectMake(0, 0, 40, 40);
        
        button.tag =1;
        [button setBackgroundImage:[UIImage imageNamed:@"button_back-iOS7"] forState:UIControlStateNormal];
        
        [self addSubview:button];
        UIImageView * line2 =[[UIImageView alloc]initWithFrame:CGRectMake(0, self.frame.size.height, self.frame.size.width, 2)];
        line2.image =[UIImage imageNamed:@"line_activity"];
        [self addSubview:line2];

        if (isShared ==YES)
        {
            UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
            
            button2.tag =2;
            [button2 setTitle:@"分享" forState:UIControlStateNormal];
            [button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            button2.backgroundColor =[UIColor magentaColor];
            
            
            [self addSubview:button2];
            [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(button.mas_top).with.offset(5);
                make.bottom.equalTo(button.mas_bottom).with.offset(-5);
                make.right.offset(-10);
                make.centerY.equalTo(button.mas_centerY);
                make.width.equalTo(@60);
            }];
        }
    }
    return self;
}
-(id)initWithBtn
{
   NSArray * titleArr =@[@"新品",@"热销",@"价格"];
   NSArray* normalArr =@[@"yuike_itemgroup_arrow_gray",@"yuike_itemgroup_arrow_gray",@"yuike_itemgroup_arrow2_gray"];
    
   NSArray * slectArr =@[@"yuike_itemgroup_arrow_black",@"yuike_itemgroup_arrow_black",@"yuike_itemgroup_arrow2_blackdown",@"yuike_itemgroup_arrow2_blackup"];
    self =[super init];
    if (self) {
      UIView*  _btnView =[[UIView alloc]init];
        _btnView.frame =CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, 50);
        _btnView.backgroundColor =backColor;
        
        UIImageView * line =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, _btnView.frame.size.width, 2)];
        line.image =[UIImage imageNamed:@"line_activity"];
        [_btnView addSubview:line];
        UIImageView * line2 =[[UIImageView alloc]initWithFrame:CGRectMake(0, _btnView.frame.size.height, _btnView.frame.size.width, 2)];
        line2.image =[UIImage imageNamed:@"line_activity"];
        [_btnView addSubview:line2];
        
        
        UIButton * lastBtn;
        for (int i = 0; i < 3; i++)
        {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.tag =i+1;
            [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            [_btnView addSubview:button];
            
            UILabel * lab =[[UILabel alloc]init];
            lab.font =[UIFont systemFontOfSize:13];
            lab.text =titleArr[i];
            [button addSubview:lab];
            
            [button mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.offset(0);
                make.bottom.offset(0);
                
                if (lastBtn) {
                    //存在的话说明第二个按钮起...
                    make.left.equalTo(lastBtn.mas_right).with.offset(0);
                    make.width.equalTo(lastBtn.mas_width);
                }
                else
                {
                    //不存在说明第一个
                    make.left.offset(0);
                }
                if (i==2) {
                    make.right.offset(0);
                }
                
            }];
            
            [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.offset(10);
                make.bottom.offset(10);
                make.centerX.equalTo(button.mas_centerX).with.offset(20);
                make.width.equalTo(@60);
            }];
            lastBtn =button;
            
            UIImageView * imageView =[[UIImageView alloc]init];
            imageView.center =CGPointMake(lab.frame.size.width+lab.frame.origin.x, lab.center.y);
            imageView.tag =i+20;
            
            [button addSubview:imageView];
            
            if (i==0)
            {
                lab.textColor =[UIColor magentaColor];
                imageView.image =[UIImage imageNamed:slectArr[i]];
            }
            else
            {
                lab.textColor =[UIColor blackColor];
                imageView.image =[UIImage imageNamed:normalArr[i]];
            }
            
            
            imageView.userInteractionEnabled =NO;
            lab.userInteractionEnabled = NO;
        }

    }
    return self;
}
//-(void)btn
//{
//    [_view.]
//}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
